package com.zzk.lanouhn.myapplication1.adapters;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.zzk.lanouhn.myapplication1.R;
import com.zzk.lanouhn.myapplication1.activity.FindDetailsActivity;
import com.zzk.lanouhn.myapplication1.modles.FindDetailsXiaotuModle;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lanouhn on 16/9/12.
 */
public class FindXiaotuTravelsAdapter extends RecyclerView.Adapter<FindXiaotuTravelsAdapter.Myholder> {
    private Context context;
    private List<FindDetailsXiaotuModle.TripsBean> modle = new ArrayList<>();

    public FindXiaotuTravelsAdapter(Context context, List<FindDetailsXiaotuModle.TripsBean> modle) {
        this.context = context;
        this.modle = modle;
    }

    @Override
    public Myholder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_find_xiaotu_travels, null);
        Myholder myholder = new Myholder(view);
        return myholder;
    }

    @Override
    public void onBindViewHolder(Myholder holder, final int position) {
        holder.tv_zhuti.setText(modle.get(position).getName());
        holder.tv_shijian.setText(modle.get(position).getStart_date());
        holder.tv_tianshu.setText(modle.get(position).getDays() + "天");
        holder.tv_tushu.setText(modle.get(position).getPhotos_count() + "图");
        Picasso.with(context).load(modle.get(position).getFront_cover_photo_url()).into(holder.iv);


        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //跳转事件
                int id = modle.get(position).getId();
                String xiaotu_ID = Integer.toString(id);
                Intent intent = new Intent(context, FindDetailsActivity.class);
                intent.putExtra("xiaotu_ID", xiaotu_ID);
                context.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return modle.size();
    }

    public class Myholder extends RecyclerView.ViewHolder {

        private TextView tv_zhuti, tv_shijian, tv_tianshu, tv_tushu;
        private ImageView iv;

        public Myholder(View itemView) {
            super(itemView);
            iv = (ImageView) itemView.findViewById(R.id.find_xiaotu_travels_iv);
            tv_zhuti = (TextView) itemView.findViewById(R.id.find_xiaotu_travels_tv_zhuti);
            tv_shijian = (TextView) itemView.findViewById(R.id.find_xiaotu_travels_tv_shijian);
            tv_tianshu = (TextView) itemView.findViewById(R.id.find_xiaotu_travels_tv_tianshu);
            tv_tushu = (TextView) itemView.findViewById(R.id.find_xiaotu_travels_tv_tushu);
        }
    }
}
